// =============================================================
// client-server model using Coord
// ---------------------------------------
// Author : Woo-Hyun Kim
// Email : woorung@icu.ac.kr or woorung@nhncorp.com
// Date : Oct. 29, 2008
// =============================================================
#include <iostream>

#include "discovery/Coord.h"

int main(int argc, char **argv)
{
	pid_t pid = fork();
	if(pid==0) { // client 
		Coord myspace("myspace");
		myspace.autoclean(false);

		for(int i=0;;i++) {
			pair<string,string> send_msg;
			send_msg.first = "myspace.server";

			pair<string,string> rec_msg;
			rec_msg.first = "myspace.client";

			send_msg.second = "this is client msg";
			myspace.write(send_msg);
			myspace.take(rec_msg);

			cout << "[client]" << rec_msg.second << "(" << i << ")" << endl;
		}

		exit(1);
	}
	else if(pid>0) { // server
		Coord myspace("myspace");
		myspace.autoclean(false);

		for(int i=0;;i++) {
			pair<string,string> send_msg;
			send_msg.first = "myspace.client";

			pair<string,string> rec_msg;
			rec_msg.first = "myspace.server";

			myspace.take(rec_msg);
			cout << "[server]" << rec_msg.second << "(" << i << ")" << endl;

			send_msg.second = "this is server msg";
			myspace.write(send_msg);
		}
	}

        return 1;
}
